import baseUrl from "@/api/baseUrl";
import request from "@/utils/request";
import fr from "element-ui/src/locale/lang/fr";

export function create_edition(token, edition, gameEditionProfile, gameId, isReleased) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/createEdition',
            method: 'post',
            headers: {
                Authorization: token
            },
            data: {
                edition: edition,
                gameEditionProfile: gameEditionProfile,
                gameId: gameId,
                isReleased: isReleased,
            }
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}

export function delete_discount(token, discountId) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/deleteDiscount?discountId='+discountId,
            method: 'get',
            headers: {
                Authorization: token,
                // discountId: discountId,
            },
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}

export function delete_edition(token, gameSourceId) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/deleteEdition?gameSourceId='+gameSourceId,
            method: 'post',
            headers: {
                Authorization: token,
            },
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}

export function delete_game_source(token, edition) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/deleteGameSource?edition='+edition,
            method: 'post',
            headers: {
                Authorization: token,
            },
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}

export function create_game(token, announceTime, isAnnounced, isReleased, name, price, profile, releaseTime, typeId) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/game/createGame',
            method: 'post',
            headers: {
                Authorization: token,
            },
            data: {
                announceTime: announceTime,
                isAnnounced: isAnnounced,
                isReleased: isReleased,
                name: name,
                price: price,
                profile: profile,
                releaseTime: releaseTime,
                typeId: typeId
            }
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}

export function update_game(token, announceTime, isAnnounced, isReleased, name, price, profile, releaseTime, typeId) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/game/updateGame',
            method: 'post',
            headers: {
                Authorization: token,
            },
            data: {
                announceTime: announceTime,
                isAnnounced: isAnnounced,
                isReleased: isReleased,
                name: name,
                price: price,
                profile: profile,
                releaseTime: releaseTime,
                typeId: typeId
            }
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}

export function delete_game(token, gameId) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/game/deleteGame?gameId='+gameId,
            method: 'get',
            headers: {
                Authorization: token,
            },
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}

export function game_info(token, gameId) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/game/info?gameId='+gameId,
            method: 'get',
            headers: {
                Authorization: token,
            },
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}

export function index(token, pageNum, pageSize) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/index?pageNum='+pageNum+'&pageSize='+pageSize,
            method: 'get',
            headers: {
                Authorization: token,
            },
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}

export function select_discount_info(token, gameId) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/selectDiscountInfo?gameId='+gameId,
            method: 'get',
            headers: {
                Authorization: token,
            },
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}

export function select_game_source(token, edition) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/selectGameSource?edition='+edition,
            method: 'post',
            headers: {
                Authorization: token,
            },
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}

export function set_discount(token, from_time, gameId, price, to_time) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/setDiscount?from_time='+from_time+'&gameId='+gameId+'&price='+price+'&to_time'+to_time,
            method: 'post',
            headers: {
                Authorization: token,
            },
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}

export function update_discount_info(token, discountId, from_time, gameId, price, to_time) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/updateDiscountInfo?discountId='+discountId+'&from_time='+from_time+'&price='+price+'&to_time='+to_time,
            method: 'get',
            headers: {
                Authorization: token,
            },
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}

export function update_edition(token, edition, gameEditionProfile, gameId, isReleased, gameSourceId) {
    return new Promise((resolve, reject) => {
        request({ //使用封装好的 axios 进行网络请求
            url: baseUrl + 'api/developer/updateEdition?gameSourceId=' + gameSourceId,
            method: 'post',
            headers: {
                Authorization: token,
            },
            data: {
                edition: edition,
                gameEditionProfile: gameEditionProfile,
                gameId: gameId,
                isReleased: isReleased,
            }
        }).then(response => { //使用 user 接口进行网络请求
            resolve(response) //将结果封装进 Promise
        }).catch(error => {
            reject(error)
        })
    })
}